<%
layout("/layouts/platform.html"){
%>
<section class="content-wrap bg-white">
    <header class="header navbar bg-white shadow">
        <div class="btn-group tool-button">
            <button class="btn btn-danger navbar-btn" onclick="delCheck()"><i class="ti-close"></i> 删除选中</button>
        </div>
        <a class="btn btn-primary navbar-btn"
			href="${base}/platform/losys/insurance/add" data-pjax><i
			class="ti-plus"></i> 添加保价</a>
		<div class="btn-group tool-button" style="padding-left: 10px;" id="taobao">
			<div class="input-group"
				style="width: 250px; float: left; padding-left: 5px; padding-right: 5px">
				<span class="input-group-addon">物流公司</span> <select id="logisticsid"
					class="form-control" onchange="search()">
					<% for(items in obj){%>
					   <option value="${items.id}">${items.name}</option>
					<%}%>
				</select>
			</div>
		</div>
        <!-- <div class="pull-right offscreen-right">
            <button class="btn btn-primary navbar-btn" onclick="sublime.toggleFilter('.cd-panel')"><i
                    class="fa fa-sliders"></i> 筛选
            </button>
        </div> -->
    </header>
    <div class=panel-body style="padding-top: 50px;">
        <div class="table-responsive no-border">
            <input id="unitid" type="hidden">
            <table class="table table-bordered table-striped mg-t datatable">
                <thead>
                <tr>
                    <th>运算符</th>
                    <th>保价</th>
                    <th>收费</th>
                    <th>操作</th>
            </table>
        </div>
    </div>
</section>
<!-- 删除价格分组 -->
<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">删除保价</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        确定删除该保价吗？ <br/>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button id="okDel" type="button" class="btn btn-primary" data-loading-text="正在删除...">确 定</button>
            </div>
        </div>
    </div>
</div>
<!-- 删除选中用户 -->
<div id="dialogDeleteCheck" class="modal fade bs-modal-lg" tabindex="-2" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">删除保价</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12 mb10">
                       确定删除该保价吗？
                    </div>
                    <div class="col-xs-12">
                        <ul id="checkedUser" class="list-group"></ul>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button id="ok" type="button" class="btn btn-primary" data-loading-text="正在删除...">确 定</button>
            </div>
        </div>
    </div>
</div>


<script language="JavaScript">
    var datatable;
    function initDatatable() {
        datatable = $('.datatable').DataTable({
            "dom": '<"toolbar">frtip',
            "searching":false,
            "processing": false,
            "serverSide": true,
            "select": true,
            "ordering": true,
            "language": {
                "url": "${base}/assets/plugins/datatables/cn.json"
            },
            "preDrawCallback": function () {
                sublime.showLoadingbar($(".main-content"));
            },
            "drawCallback": function () {
                sublime.closeLoadingbar($(".main-content"));
            },
            "ajax": {
                "url": "${base}/platform/losys/insurance/data",
                "type": "post",
                "data": function (d) {
                    d.logisticsid = $("#logisticsid").val(); 
               }
            },
            "order": [[0, "desc"]],
            "columns": [
                {"data": "operator", "bSortable": true},
                {"data": "insurance", "bSortable": true},
                {"data": "value", "bSortable": true},
            ],
            "columnDefs": [
            	{
                    "render": function (data, type, row) {
                    	if(row.type === '1'){
                    		return data + "元";
                    	}else {
                    		return data*100 + "%";
                    	}
                    },
                    "targets": 2
                },
            	{
                    "render": function (data, type, row) {
                        return '<div class="btn-group"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">' +
                                ' <i class="ti-settings"></i> <span class="ti-angle-down"></span></button><ul class="dropdown-menu" role="menu">' +
                                '<li><a href="${base}/platform/losys/insurance/edit/' + row.insuranceid + '/'+ row.id +'" data-pjax>修改</a></li>' +
                                '<li><a href="javascript:;" onclick="del(\'' + row.id + '\')">删除</a></li>' +
                                '</ul></div>';
                    },
                    "targets": 3
                }
            ]
        });
        datatable.on('click', 'tr', function () {
            $(this).toggleClass('selected');
        });
        $("#searchBtn").on('click', function () {
            datatable.ajax.reload();
        });
    }
    function search() {
        datatable.ajax.reload();
    }
    function del(id) {
        var dialog = $("#dialogDelete");
        dialog.modal("show");
        dialog.find("#okDel").unbind("click");
        dialog.find("#okDel").bind("click", function (event) {
            var btn = $(this);
            btn.button("loading");
            $.post("${base}/platform/losys/insurance/delete/" + id, {}, function (data) {
                if (data.code == 0) {
                    datatable.ajax.reload(null,false);
                } else {
                    Toast.error(data.msg);
                }
                //重置按钮状态，关闭提示框
                btn.button("reset");
                dialog.modal("hide");
            }, "json");
        });
    }
    
    function delCheck() {
        var chks = datatable.rows('.selected').data();
        if (chks.length > 0) {
            var ids = [];
            $.each(chks, function (i, n) {
                ids.push(n.id);
            });
            var dialog = $("#dialogDeleteCheck");
            dialog.modal("show");
            dialog.find("#ok").unbind("click");
            dialog.find("#ok").bind("click", function (event) {
                var btn = $(this);
                btn.button("loading");
                $.post("${base}/platform/losys/insurance/delete", {ids: ids.toString()}, function (data) {
                    if (data.code == 0) {
                        datatable.ajax.reload(null,false);
                    } else {
                        Toast.error(data.msg);
                    }
                    btn.button("reset");
                    dialog.modal("hide");
                }, "json");
            });
        } else {
            Toast.warning("请先选择要删除的保价！");
        }
    }
    $(document).ready(function () {
        initDatatable();
        $("#dialogUserDetail").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
        $("#dialogUserRightDetail").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
        $("#dialogPaasword").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
        $('#homeDetail').on('hidden.bs.modal',function(){
            $(this).removeData("bs.modal");
        });
    });

</script>
<%}%>
